<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" type="text/css" href="../js/layui/css/layui.css"/>
	</head>
	<body>
		<div class="layui-container">
			<div class="layui-row">
				<div class="layui-col-md6 layui-col-lg-offset3">
					<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
					  <legend>完善信息</legend>
					</fieldset>
					<div class="layui-form">
						<form action="" method="POST " enctype="multipart/form-data" class="layui-form layui-form-pane" id="add_info">
							<div class="layui-form-item">
							    <label class="layui-form-label">医疗机构</label>
							    <div class="layui-input-block">
							      <input type="text" name="hospital" autocomplete="off" lay-verify="required" placeholder="请输入医院" class="layui-input">
							    </div>
							</div>
							<!-- doc_rank -->
							<div class="layui-form-item">
							    <label class="layui-form-label">职位</label>
							    <div class="layui-input-block">
							      <select name="doc_rank" lay-filter="doc_rank">
							      			<option value="医师" >医师</option> 
													<option value="主治医师">主治医师</option>
													<option value="主任医师">主任医师</option>
													<option value="护士" >护士</option>
													<option value="护师" >护师</option>
													<option value="协助工作者" >协助工作者</option>
							      </select>
							    </div>
							</div>
							
							<div class="layui-form-item">
							    <label class="layui-form-label">资格证编号</label>
							    <div class="layui-input-inline">
							      <input type="text" name="zS_number" autocomplete="off" lay-verify="required" lay-reqtext="资格证编号不能为空" placeholder="请输入编号" class="layui-input">
							    </div>
								<div class="layui-input-inline" style="padding: 10px;">
									<a href="http://zgcx.nhc.gov.cn:9090/doctor" target="_blank" style="color: red;">忘记编号?</a>
								</div>
							</div>
							
							 <div class="layui-form-item layui-form-text">
							    <label class="layui-form-label">自我介绍</label>
							    <div class="layui-input-block">
							      <textarea placeholder="请输入内容(专科方向)" name="introduce" lay-verify="required" class="layui-textarea"></textarea>
							    </div>
							  </div>
							<!-- 上传照片 -->
							<div class="layui-form-item">
								<div class="layui-col-md3">
									<input class="aload" type='button' value='上传头像照片' onClick='javascript:$("#self_photo").click();' />
									<input type="file" style="display: none;" lay-verify="required" name="self_photo" value=""  accept=".jpg,.png,.jpeg" id="self_photo" onchange="upload(this)"/>
								</div>
								<div class="layui-col-md3 layui-col-lg-offset3" style="border: 1px solid gray;">
									<img src="" id="self_photo_show" width="100%" height="160px" alt="图片像素不超过300*150">
								</div>
							</div>
							<!-- 上传签名 -->
							<div class="layui-form-item">
								<div class="layui-col-md3">
									<input class="aload" type='button' value='上传签名照片' onClick='javascript:$("#sign_photo").click();' />
									<input type="file" style="display: none;" name="sign_photo" lay-verify="required" accept=".jpg,.png,.jpeg" id="sign_photo" value="" onchange="upload(this)"/>
								</div>
								<div class="layui-col-md12" style="border: 1px solid gray;">
									<img src="" id="sign_photo_show" width="100%" height="150px" >
								</div>
							</div>
							<button type="submit"  lay-submit lay-filter="formDemo" class="layui-btn layui-btn-normal" id="submit" style="width: 100%;">
								提交
							</button>
						</form>
					</div>
				</div>
			</div>		
		</div>
		
		<script src="../js/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			function upload(dom_name){
				var fileInput = document.getElementById(dom_name.id);
				var show = dom_name.id+"_show";
				
				var file = fileInput.files[0];
				if (file.size/1024 > 1024) {
            alert("文件大小不能大于1M！");
            file.value = "";
            return false;
        }else if (file.size <= 0) {
            alert("文件大小不能为0M！");
            file.value = "";
            return false;
        } else {
					//创建读取文件的对象
					var reader = new FileReader();         
					//创建文件读取相关的变量
					var imgFile;         
					//为文件读取成功设置事件
					reader.onload=function(e) {
						// alert('文件读取完成');
						imgFile = e.target.result;
						//console.log(imgFile);
						$("#"+show).attr('src',imgFile);
					 };
						//正式读取文件
					reader.readAsDataURL(file);
				}
				
			}
			
			
			
			layui.use(['layer', 'form', 'element','upload'],function(){
				//加载layui表单元素
				var form = layui.form,
					layer = layui.layer,
					element = layui.element;
					form.render();
			
				form.on("submit(formDemo)", function (data) {
					
					var formData = new FormData($("#add_info")[0]);
					formData.append("phone",localStorage.getItem("FDSMS"));
					 $.ajax({   //http://123.56.67.48:8080/completeDocInfo //http://homedoc:8881/tp5/public/index.php/doc/doc/addInfo
							url:'http://123.56.67.48:8080/completeDocInfo',
							method:'POST',
							cache: false, 
							contentType:false,
							processData: false,
							data:formData,
							success:function(res){
								console.log(res);
								if(JSON.parse(res).code == 1){
									alert("上传成功");
									window.location.reload();  
								}
								else {
									alert("上传失败请重新上传");
								}
							},              
							error:function (res) {
									alert("上传失败"); 
							}           
						}); 
					return false;  
				});	
			});
		</script>
	</body>
</html>
